#include "Geometry.h"

Mat4x4 Mat4x4::g_Identity = Mat4x4(true);

void Mat4x4::SetPosition(Vec4 const &pos)
{
	D3DXMatrixTranslation(this, pos.x, pos.y, pos.z);
}
void Mat4x4::SetPosition(Vec3 const &pos)
{
	D3DXMatrixTranslation(this, pos.x, pos.y, pos.z);
}
void Mat4x4::SetLookAt(Vec3 target)
{
	D3DXMatrixLookAtLH(this, &this->GetPosition(), &target, &Vec3(0,1,0));
}

Vec3 Mat4x4::GetForward() const
{
	Vec3 forward;
	forward.x = m[2][0];
	forward.y = m[2][1];
	forward.z = m[2][2];
	return forward;
}
Vec3 Mat4x4::GetPosition() const
{
	Vec3 forward;
	forward.x = m[3][0];
	forward.y = m[3][1];
	forward.z = m[3][2];
	return forward;
}
Vec4 Mat4x4::Xform(const Vec4 &v) const
{
	Vec4 transform;
	D3DXVec4Transform(&transform, &v, this);
	return transform;
}
Vec3 Mat4x4::Xform(const Vec3 &v) const
{
	Vec4 t;
	D3DXVec3Transform(&t, &v, this);
	return Vec3(t.x,t.y,t.z);
}
Mat4x4 Mat4x4::Inverse() const
{
	Mat4x4 t;
	//finish
	return t;
}
void Mat4x4::RotateX(const float radians)
{
	Mat4x4 rot;
	D3DXMatrixRotationX(&rot, radians);
	D3DXMatrixMultiply(this,&rot,this);
}
void Mat4x4::RotateY(const float radians)
{
	Mat4x4 rot;
	D3DXMatrixRotationY(&rot, radians);
	D3DXMatrixMultiply(this,&rot,this);
}
void Mat4x4::RotateZ(const float radians)
{
	Mat4x4 rot;
	D3DXMatrixRotationZ(&rot, radians);
	D3DXMatrixMultiply(this,&rot,this);
}
void Mat4x4::RotateXYZ(const float x, const float y, const float z)
{
	Mat4x4 rot;
	D3DXMatrixRotationYawPitchRoll(&rot, y,x,z);
	D3DXMatrixMultiply(this,&rot,this);
}
void Mat4x4::BuildTranslation(const Vec3 &pos)
{
	D3DXMatrixTranslation(this,pos.x,pos.y,pos.z);
}
void Mat4x4::BuildTranslation(const float x, const float y, const float z )
{
	D3DXMatrixTranslation(this,x,y,z);
}
void Mat4x4::BuildRotationX(const float radians)
{
	D3DXMatrixRotationX(this,radians);
}
void Mat4x4::BuildRotationY(const float radians)
{
	D3DXMatrixRotationY(this,radians);
}
void Mat4x4::BuildRotationZ(const float radians)
{
	D3DXMatrixRotationZ(this,radians);
}
void Mat4x4::BuildRotationXYZ(const float y, const float x, const float z)
{
	D3DXMatrixRotationYawPitchRoll(this,y,x,z);
}
